#!/usr/bin/env python
# coding=utf-8
#__author__ = 'Yunchao Ling'

infile1=open("D:/data/if/journal_if.txt","r")
jr={}
infile1.readline()
for line in infile1:
    line=line.rstrip("\n")
    splitline=line.split("\t")
    issn=splitline[1]
    impactfactor=splitline[23]
    if issn!="":
        jr[issn]=impactfactor
infile1.close()

outfile=open("D:/data/if/sci_journal.tsv","w")
infile2=open("D:/data/if/Journal.tsv","r")
infile2.readline()
for line in infile2:
    line=line.rstrip("\n")
    splitline=line.split("\t")
    issn1=splitline[3]
    issn2=splitline[4]
    if jr.has_key(issn1):
        outfile.write(line+"\t"+jr[issn1]+"\n")
        outfile.flush()
    elif jr.has_key(issn2):
        outfile.write(line+"\t"+jr[issn2]+"\n")
        outfile.flush()
infile2.close()
outfile.close()